package com.skrabacz.kinetic.buisness.logic;

import static org.junit.Assert.*;

import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

public class SimpleBallShould {

	private final static double PRECISION = 0.0000001;
	private static Point node;
	private Ball ball;

	@BeforeClass
	public static void setupBeforClass() {
		node = new Node(0d, new Coordinates2D(0, 0));
	}

	@Before
	public void setUpBeforeSingleTest() {
		ball = new SimpleBall();
	}

	@Test
	public void setDefaultSpeedToZero() throws Exception {
		assertEquals(0, ball.getSpeed(), PRECISION);
	}

	@Test
	public void setDefaultDirectionToNorth() throws Exception {
		assertEquals(Direction.North, ball.getDirection());
	}

	@Test
	public void beAbleToMoveIntoSettedDirection() throws Exception {
		assertTrue(SimpleBallBuilder.simpleBall().withBoard(new Matrix(2, 2)).build()
				.moveToDirection(Direction.South));
	}

	@Test
	public void returnFalseWhenMoveWasBeyondBoard() throws Exception {
		assertFalse(ball.moveToDirection(Direction.North));
	}

	@Test
	public void checkReachabilityOfPoint() throws Exception {
		ball = SimpleBallBuilder.simpleBall().withBoard(new Matrix(2, 2)).build();
		node = new Node(0d, new Coordinates2D(0, 0));
		assertTrue(ball.isReachable(node, Direction.East));
		assertFalse(ball.isReachable(node, Direction.North));
		assertTrue(ball.isReachable(node, Direction.South));
		assertFalse(ball.isReachable(node, Direction.West));
	}

	@Test
	public void changeCurrentPointAfterMove() throws Exception {
		ball = SimpleBallBuilder.simpleBall().withBoard(new Matrix(2, 2)).withCurrentPosition(new Node()).build();
		assertTrue(ball.moveToDirection(Direction.South));
		Point p = ball.getCurrentPosition();
		Board board = ball.getBoard();
		assertEquals(board.getPoint(1, 0), p);
	}
}
